<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script>
    var div = document.createElement("div");
    var heightDiv = document.createAttribute("height");
    var widthDiv = document.createAttribute("width");
    var border= document.createAttribute("border");
    border.nodeValue="1px solid black";
    div.setAttributeNode(border)
    heightDiv.nodeValue="300px";
    widthDiv.nodeValue="300px";
    div.setAttributeNode(heightDiv);
    div.setAttributeNode(widthDiv);
    var img = document.createElement("img");
    var src = document.createAttribute("src");
    src.nodeValue="../imgs/1.jpg";
    img.setAttributeNode(src);
    var height = document.createAttribute("height");
    var width = document.createAttribute("width");
    height.nodeValue="200px";
    width.nodeValue="200px";
    img.setAttributeNode(height);
    img.setAttributeNode(width);
    // var attr2=document.createAttribute("style");
    // img.style.width="200px";
    // img.style.height="200px";
    var title = document.createAttribute("title");
    title.nodeValue="这是一张图片";
    img.setAttributeNode(title);
    var alt = document.createAttribute("alt");
    alt.nodeValue="图片已过期";
    img.setAttributeNode(alt);

    div.appendChild(img);
    var body = document.getElementsByTagName("body")[0];
     body.appendChild(div);
</script>
</body>
</html>